/*
 * einkservice.h
 *
 *  Created on: Apr 23, 2023
 *      Author: ycqia
 */

#ifndef INCLUDE_EINKSERVICE_H_
#define INCLUDE_EINKSERVICE_H_

// Profile Parameters
#define EINKSERVICE_STATUS              0           // RW uint8_t - Profile Characteristic 1 value
#define EINKSERVICE_TIMESTAMP           1           // RW uint8_t - Profile Characteristic 2 value
#define EINKSERVICE_CFG                 2           // RW uint8_t - Profile Characteristic 3 value
#define EINKSERVICE_HTNOTIFY            3           // RW uint8_t - Profile Characteristic 4 value
#define EINKSERVICE_CHAR5               4           // RW uint8_t - Profile Characteristic 4 value

// Simple Profile Service UUID
#define EINKSERVICE_SERV_UUID           0xFFE1

// Key Pressed UUID
#define EINKSERVICE_STATUS_UUID         0xFFE1
#define EINKSERVICE_TIMESTAMP_UUID      0xFFE2
#define EINKSERVICE_CFG_UUID            0xFFE3
#define EINKSERVICE_HTNOTIFY_UUID       0xFFE4
#define EINKSERVICE_CHAR5_UUID          0xFFE5

// Simple Keys Profile Services bit fields
#define EINKSERVICE_SERVICE             0x00000001

// Length of characteristic in bytes ( Default MTU is 23 )
#define EINKSERVICE_STATUS_LEN          1
#define EINKSERVICE_TIMESTAMP_LEN       4
#define EINKSERVICE_CFG_LEN             6
#define EINKSERVICE_HTNOTIFY_LEN        4
#define EINKSERVICE_CHAR5_LEN           5


// Callback when a characteristic value has changed
typedef void (*einkServiceChange_t)(uint8_t paramID, uint8_t *pValue, uint16_t len);

typedef struct
{
    einkServiceChange_t pfnEinkServiceChange; // Called when characteristic value changes
} einkServiceCBs_t;

/*********************************************************************
 * API FUNCTIONS
 */

/*
 * EinkService_AddService- Initializes the Simple GATT Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 */

extern bStatus_t EinkService_AddService(uint32_t services);

/*
 * EinkService_RegisterAppCBs - Registers the application callback function.
 *                    Only call this function once.
 *
 *    appCallbacks - pointer to application callbacks.
 */
extern bStatus_t EinkService_RegisterAppCBs(einkServiceCBs_t *appCallbacks);

/*
 * EinkService_SetParameter - Set a Simple GATT Profile parameter.
 *
 *    param - Profile parameter ID
 *    len - length of data to right
 *    value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16_t will be cast to
 *          uint16_t pointer).
 */
extern bStatus_t EinkService_SetParameter(uint8_t param, uint8_t len, void *value);

/*
 * EinkService_GetParameter - Get a Simple GATT Profile parameter.
 *
 *    param - Profile parameter ID
 *    value - pointer to data to write.  This is dependent on
 *          the parameter ID and WILL be cast to the appropriate
 *          data type (example: data type of uint16_t will be cast to
 *          uint16_t pointer).
 */
extern bStatus_t EinkService_GetParameter(uint8_t param, void *value);

/*
 * einkService_Notify - Send notification.
 *
 *    connHandle - connect handle
 *    pNoti - pointer to structure to notify.
 */
extern bStatus_t einkService_Notify(uint16_t connHandle, attHandleValueNoti_t *pNoti);
#endif /* INCLUDE_EINKSERVICE_H_ */
